﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MovieRental.Entities;
using MovieRental.BuisnessComponents;

namespace MovieRental.EnhancedEntities
{
    public class Edition : BaseEnhancedEntity<EditionInfo>
    {
        public Edition(EditionInfo edition) : base(edition)
        {
        }

        protected override void EntityChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            OnPropertyChanged("MediaTypeName");
        }

        public double DiscountValue
        {
            get { return ComponentFactory.Instance.GetTemporaryDiscountComponent().GetAvailableDiscountValue(Entity); }
        }

        public string MediaTypeName
        {
            get { return ComponentFactory.Instance.GetMediaTypeComponent().Get(Entity.MediaTypeId).Name; }
        }

        public int InStockQuantity
        {
            get { return ComponentFactory.Instance.GetEditionComponent().RemainingQuantity(Entity); }
        }

        public string MovieTitle
        {
            get
            {
                var movie = ComponentFactory.Instance.GetMovieComponent().Get(Entity.MovieId);
                return (movie == null) ? null : movie.Title;
            }
        }
    }
}
